package duhosdebuggolok;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class AntHedgehogPainter implements Painter{
	
	private static BufferedImage anthedgehogImage0 = null;
	private static BufferedImage anthedgehogImage1 = null;
	private static BufferedImage anthedgehogImage2 = null;
	private static BufferedImage anthedgehogImage3 = null;
	private static BufferedImage anthedgehogImage4 = null;
	private static BufferedImage anthedgehogImage5 = null;
	private AntHedgehog antHedgehog;
	
	private static void loadImage() {
		try {
			anthedgehogImage0 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangyaszsun0_.png"));
			anthedgehogImage1 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangyaszsun1_.png"));
			anthedgehogImage2 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangyaszsun2_.png"));
			anthedgehogImage3 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangyaszsun3_.png"));
			anthedgehogImage4 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangyaszsun4_.png"));
			anthedgehogImage5 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\hangyaszsun5_.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
}
	
	public AntHedgehogPainter(AntHedgehog ah) {
		antHedgehog = ah;
		if (anthedgehogImage0 == null)
			loadImage();
	}
	
	public boolean paint(Graphics2D g){
		if(antHedgehog.getActive()) {
			Point coord = antHedgehog.getCoord();
			int angle = antHedgehog.getAngle();
			//AffineTransform affineTransform = new AffineTransform();
			Point c = GamePanel.calculate(coord);
			//affineTransform.translate(0,0);
			//affineTransform.translate((c.x+3), (c.y-7));
			//affineTransform.rotate(Math.toRadians(angle*60-180), 0, 0);
			//affineTransform.translate(-25, 0);
			//affineTransform.scale(2, 2);
			switch (angle) {
			case 0:
				g.drawImage(anthedgehogImage0, c.x-17, c.y-33, null);
				break;
			case 1:
				g.drawImage(anthedgehogImage1, c.x-35, c.y-25, null);
				break;
			case 2:
				g.drawImage(anthedgehogImage2, c.x-35, c.y+5, null);
				break;
			case 3:
				g.drawImage(anthedgehogImage3, c.x-15, c.y+15, null);
				break;
			case 4:
				g.drawImage(anthedgehogImage4, c.x+3, c.y+10, null);
				break;
			case 5:
				g.drawImage(anthedgehogImage5, c.x+5, c.y-15, null);
				break;
			}
		}
		return true;
	}
}